local skel = fk.CreateSkill {
  name = "rmt__douma",
  dynamic_desc = function (self, player, lang)
    local name = player:getMark("rmt__douma_record")
    if type(name) == "string" then
      return "rmt__douma_inner:" .. name
    end
  end,
}

Fk:loadTranslationTable{
  ["rmt__douma"] = "斗？",
  [":rmt__douma"] = "锦囊牌或伤害牌对你生效前，你可以弃置此牌牌名字数张【嘭！】令之无效；出牌阶段限一次，你可以将一张【嘭！】当作上次以此法响应的牌使用。",

  [":rmt__douma_inner"] = "锦囊牌或伤害牌对你生效前，你可以弃置此牌牌名字数张【嘭！】令之无效；出牌阶段限一次，你可以将一张【嘭！】当作上次以此法响应的牌（{1}）使用。",

  ["#rmt__douma-cost"] = "斗？：你可以弃置%arg张【嘭！】令%arg2无效",
  ["#rmt__douma"] = "斗？：将一张【嘭！】当【%arg】使用",
}

skel:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  --pattern = ".|.|.|.|.|trick,basic",
  prompt = function (self, player)
    local mark = player:getMark("rmt__douma_record")
    if type(mark) == "string" then
      return "#rmt__douma:::"..mark
    end
    return " "
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).name == "peng"
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return nil end
    local mark = player:getMark("rmt__douma_record")
    if Fk.all_card_types[mark] == nil then return nil end
    local c = Fk:cloneCard(mark)
    c.skillName = skel.name
    c:addSubcard(cards[1])
    return c
  end,
  times = function (self, player)
    return 1 - player:usedEffectTimes(self.name, Player.HistoryPhase)
  end,
  enabled_at_play = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryPhase) == 0
    and player:getMark("rmt__douma_record") ~= 0
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addEffect(fk.PreCardEffect, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and not player:isKongcheng() and data.to == player then
      return data.card.type == Card.TypeTrick or data.card.is_damage_card or data.card.name == "peng"
    end
  end,
  on_cost = function (self, event, target, player, data)
    local num = Fk:translate(data.card.trueName, "zh_CN"):len()
    if num == 0 then return false end
    local cards = player.room:askToDiscard(player, {
      min_num = num, max_num = num, skill_name = skel.name, pattern = "peng", cancelable = true, skip = true,
      prompt = "#rmt__douma-cost:::"..num..":"..data.card:toLogString(),
    })
    if #cards == num then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "rmt__douma_record", data.card.name)
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
    data:setNullified(player)
  end,
})

return skel
